package com.liuyu.common.framework.iinsure.mybatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.google.common.collect.Lists;
import com.liuyu.commmon.framework.power.cloud.mybatis.interceptor.DataAuthMybatisPlusInnerInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

import java.util.List;

/**
 @Component
  * @ClassName MybatisPlusBostProcess
 * @Author: liuyu
 * @Date: Created in 2021/6/22 19:07
 * @Version: 1
 * @Modified By:
 */
public class MybatisPlusBeanPostProcess implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        BeanDefinition definition = configurableListableBeanFactory.getBeanDefinition("mybatisPlusInterceptor");
        MutablePropertyValues pv = definition.getPropertyValues();
        List<InnerInterceptor> interceptors = Lists.newArrayListWithCapacity(4);
        interceptors.add(new DataAuthMybatisPlusInnerInterceptor());
        //分页插件
        interceptors.add(new PaginationInnerInterceptor(DbType.MYSQL));
        //乐观锁
        interceptors.add(new OptimisticLockerInnerInterceptor());
        //防止全表更新与删除
        interceptors.add(new BlockAttackInnerInterceptor());
        pv.addPropertyValue("interceptors", interceptors);
    }
}
